<?php

namespace Mvc\Core\Controller;
/**
 * Created by PhpStorm.
 * User: 554665488
 * Date: 2018-6-22
 * Time: 1:30
 * @description: 系统基类控制器
 * @Author: yfl
 * @QQ 554665488
 */

abstract class Controller
{
    protected $data;
    protected $view_dir_name;//模板子目录 控制器的名子
    protected $view_file_name;//模板的文件名 控制器方法名字
    protected $view_root;//模板根目录

    public function __construct($controller, $action)
    {
        $this->view_dir_name = $controller;
        $this->view_file_name = $action;
        $this->view_root = \Mvc\Application::instance()->base_dir . '/view';

    }

    public function initialize()
    {
        
    }
    public function assign($key, $value)
    {
        $this->data[$key] = $value;
    }

    public function display($file = '')
    {
        if (empty($file)) {
            $file = strtolower($this->view_dir_name) . '/' . $this->view_file_name . '.php';
        }
        $path = $this->view_root . '/' . $file;
        extract($this->data);
        include $path;
    }
}